﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳检测详情】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳检测详情
    /// </summary>
    public abstract class AutoCheckWireropeDetailMapping : BaseMapping<CheckWireropeDetail, CheckWireropeDetailModel, CheckWireropeDetailFilterModel>
    {
        public AutoCheckWireropeDetailMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override CheckWireropeDetailModel Entity2Model(CheckWireropeDetail entity)
        {
            CheckWireropeDetailModel model = new CheckWireropeDetailModel();

            model.CheckWireropeDetailID = entity.CheckWireropeDetailID;
            model.GroupInfoID = entity.GroupInfoID;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.CheckWireropeID = entity.CheckWireropeID;
            model.SortNo = entity.SortNo;
            model.Name = entity.Name;
            model.DsCnt = entity.DsCnt;
            model.DsLa = entity.DsLa;
            model.ZjPosition = entity.ZjPosition;
            model.ZjDia = entity.ZjDia;
            model.JsjmPosition = entity.JsjmPosition;
            model.JsjmLma = entity.JsjmLma;
            model.NianJu = entity.NianJu;
            model.NianJuChange = entity.NianJuChange;
            model.OthFuShi = entity.OthFuShi;
            model.OthMoSun = entity.OthMoSun;
            model.OthQiTa = entity.OthQiTa;
            model.OthZongHe = entity.OthZongHe;
            model.Attr_FilesList = entity.Attr_Files.GetFileList();
            model.DsCntAdd = entity.DsCntAdd;
            model.AllCntAdd = entity.AllCntAdd;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override CheckWireropeDetail Model2Entity(CheckWireropeDetailModel model)
        {
            CheckWireropeDetail entity = new CheckWireropeDetail();

            entity.CheckWireropeDetailID = model.CheckWireropeDetailID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.CheckWireropeID = model.CheckWireropeID;
            entity.SortNo = model.SortNo;
            entity.Name = model.Name;
            entity.DsCnt = model.DsCnt;
            entity.DsLa = model.DsLa;
            entity.ZjPosition = model.ZjPosition;
            entity.ZjDia = model.ZjDia;
            entity.JsjmPosition = model.JsjmPosition;
            entity.JsjmLma = model.JsjmLma;
            entity.NianJu = model.NianJu;
            entity.NianJuChange = model.NianJuChange;
            entity.OthFuShi = model.OthFuShi;
            entity.OthMoSun = model.OthMoSun;
            entity.OthQiTa = model.OthQiTa;
            entity.OthZongHe = model.OthZongHe;
            entity.Attr_Files = model.Attr_FilesList.GetFileString();
            entity.DsCntAdd = model.DsCntAdd;
            entity.AllCntAdd = model.AllCntAdd;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<CheckWireropeDetail> FilterModel2Where(CheckWireropeDetailFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._CheckWireropeDetailID.HasValue)
            {
                where = where.And(x => x.CheckWireropeDetailID == filterModel._CheckWireropeDetailID.Value);
            }
            if (filterModel._CheckWireropeDetailIDs.IsNotEmpty() && filterModel._CheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }
            if (filterModel._NotCheckWireropeDetailIDs.IsNotEmpty() && filterModel._NotCheckWireropeDetailIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeDetailIDs.Contains(x.CheckWireropeDetailID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //检测基本信息
            if (filterModel._CheckWireropeID.HasValue)
            {
                where = where.And(x => x.CheckWireropeID == filterModel._CheckWireropeID.Value);
            }
            if (filterModel._CheckWireropeIDs.IsNotEmpty() && filterModel._CheckWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._CheckWireropeIDs.Contains(x.CheckWireropeID));
            }
            if (filterModel._NotCheckWireropeIDs.IsNotEmpty() && filterModel._NotCheckWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotCheckWireropeIDs.Contains(x.CheckWireropeID));
            }

            //绳名称
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            return where;
        }
        #endregion
    }
}

